package com.dq.ad.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.dq.ad.R;

/**
 * FileName: BaseAdDialogLoading
 * Author: admin
 * Date: 2021/1/29 9:46
 * Description:
 */
public class BaseAdDialogLoading extends Dialog {

    private final Activity activity;
    private String content = "视频正在加载中...";

    public BaseAdDialogLoading(@NonNull Activity a) {
        super(a, R.style.base_ad_dialog_loading);
        this.activity = a;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        setContentView(R.layout.lib_ad_dialog_loading);
        setCanceledOnTouchOutside(false);
        setCancelable(false);

        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = getScreenWidth(activity);
        lp.height = getScreenHeight(activity);
        getWindow().setAttributes(lp);

        TextView tvMsg = findViewById(R.id.tvContent);

        tvMsg.setText(content);
    }

    public BaseAdDialogLoading setContent(String c) {
        this.content = c;
        return this;
    }

    /**
     * 获取屏幕的宽度
     *
     * @param context
     * @return
     */
    public static int getScreenWidth(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        return dm.widthPixels;
    }

    /**
     * 获取屏幕的高度
     *
     * @param context
     * @return
     */
    public static int getScreenHeight(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        return dm.heightPixels;
    }

}